import { lazyReportBatch } from "../report";

export default function observerMemory() {
  const checkMemoryUsage = () => {
    if (performance.memory) {
      const memory = performance.memory;
      const reportData = {
        usedJSHeapSize: memory.usedJSHeapSize / 1024 / 1024, // 转换为 MB
        totalJSHeapSize: memory.totalJSHeapSize / 1024 / 1024,
        jsHeapSizeLimit: memory.jsHeapSizeLimit / 1024 / 1024,
        type: "performance",
        subType: "memory",
        page: window.location.href,
      };
      lazyReportBatch(reportData);
    }
  };

  // 每 5 秒检查一次内存使用情况
  setInterval(checkMemoryUsage, 5000);
}
